package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import model.World;

/**
 * This view will paint all the content from the level.
 * 
 * @author Friden
 */
public class GameView extends JPanel implements ActionListener{
	
	private static GameView instance = null;
	
	private Timer timer;
	private final World world = World.getInstance();
	
	private GameView(){
		JPanel holder = new JPanel();
		OverlayLayout layout = new OverlayLayout(holder);
		holder.setLayout(layout);
		
		MovingView moveView = new MovingView();
		LevelView levelView = new LevelView();
		
		moveView.setOpaque(false);
		levelView.setOpaque(false);
		
		holder.add(moveView);
		holder.add(levelView);
		
		add(holder);
		setVisible(true);
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		repaint();		
	}
	
	public void start(int updateInterval){
		timer = new Timer(updateInterval, this);
		timer.start();
	}
	
	public static GameView getInstance(){
		if(instance == null){
			instance = new GameView();
		}
		return instance;
	}
	
}
